﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;

namespace RpgEditor
{
    public class Sprite {

	public static  SByte STYLE_WALK = 0;

	public static  SByte STYLE_WAR = 1;

	/** 目前不支持Sprite的翻转 */
	// #ifndef SET_CLIP
	// # private static  int TRANS_NONE =
	// javax.microedition.lcdui.game.Sprite.TRANS_NONE;
	// #endif
	/** 碰撞参考点左上角X坐标 */
	static  int COLLIDE_VERTEX_X1 = 0;

	/** 碰撞参考点右下角X坐标 */
	static  int COLLIDE_VERTEX_X2 = 1;

	/** 碰撞参考点左上角Y坐标 */
	static  int COLLIDE_VERTEX_Y1 = 2;

	/** 碰撞参考点右下角Y坐标 */
	static  int COLLIDE_VERTEX_Y2 = 3;

	static Hashtable history = new Hashtable();

	/** 当前加载的所有动画片段 */
	static Hashtable spriteCache = new Hashtable();

	/** 保存所有图片的Cache */
	static Hashtable imgCache = new Hashtable();

	/** 保存所有图片fragment的Cache */
	static Hashtable fragmentCache = new Hashtable();

	/** 该精灵所用到的图片 */
        public ArrayList imgs;

	/** 该精灵用到的每一个图片的fragment */
        public ArrayList fragments;

	/** 该精灵所有帧系列 */
        public ArrayList frames;
        public int[] framesindex;
	// /** 所有帧的顶点信息(用于碰撞检查) */
	// private SByte collideVertex[][];

	/** 当前帧 */
	public SByte curframe;

	public SByte frameLength;

	public String name;

	/** 只允许内部构建,由文件中获得,不允许程序中动态生成Sprite */
        public Sprite()
        {
	}

        public Sprite(Image img, int id, SByte style)
        {
	/*	imgs = new Image[] { img };
		if (style == STYLE_WALK) {
            fragments = new SByte[1][];
            fragments[0] = new SByte[4*30];
			//fragments = {new SByte[4 * 3]};
			for (int i = 0; i < 3; i++) {
				fragments[0][i * 4 + 0] = 32;
				fragments[0][i * 4 + 1] = 16;
				fragments[0][i * 4 + 2] = MathTools
						.Int2Byte(16 * ((i + id * 3) % 3));
				fragments[0][i * 4 + 3] = MathTools
						.Int2Byte(32 * ((i + id * 3) / 3));
			}
			frames = new SByte[,,] { { { 0, 0, 0, -8, -32 } },
					{ { 0, 4, 0, -8, -32 } }, { { 0, 8, 0, -8, -32 } },
					{ { 0, 4, 0, -8, -32 } }, };
		} else if (style == STYLE_WAR) {
			int w = img.getWidth(), h = img.getHeight();
			fragments = new SByte[,] { { (SByte) h, (SByte) w, 0, 0 } };
			int wc = w >> 1;
			if (id == 0) {
				frames = new SByte[,,] {
						{ { 0, 0, 0, (SByte) -wc, (SByte) (-h) } },
						{ { 0, 0, 0, (SByte) -wc, (SByte) (-h-1) } },
						{ { 0, 0, 0, (SByte) -wc, (SByte) (-h-2) } },
						{ { 0, 0, 0, (SByte) -wc, (SByte) (-h-1) } }, };
			} else if (id == 1) {
				frames = new SByte[,,] {
						{ { 0, 0, 0, (SByte) (-wc), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc+5), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc+10), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc+5), (SByte) -h } }, };
			} else {
				frames = new SByte[,,] {
						{ { 0, 0, 0, (SByte) (-wc), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc-5), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc-10), (SByte) -h } },
						{ { 0, 0, 0, (SByte) (-wc-5), (SByte) -h } }, };
			}
		}
		frameLength = (SByte) frames.length;*/
	}

        public Sprite(String name, SByte frameLength)
        {
		this.name = name;
		this.frameLength = frameLength;
        frames = new ArrayList();
        for (int i = 0; i < frameLength; i++)
        {
            frames.Add(new ArrayList());
        }
        framesindex = new int[frameLength];
		// collideVertex = new SByte[frameLength][];
     
	}
        public String getFrameList()
        {
            String result = "";
            for (int i = 0; i < framesindex.Length ; i++)
            {
                result = result + framesindex[i];
                if (i != (framesindex.Length - 1))
                {
                    result = result + ",";
                }
            }
            return result;
        }
	/**
	 * 克隆包含有相同帧和名字的Sprite,并返回
	 */
    /*public static Sprite cloneSprite(Sprite source) {
        
        if (source == null) {
            return null;
        } else {
            Sprite sprite = new Sprite();

            sprite.imgs = source.imgs;
            sprite.fragments = source.fragments;
            sprite.frames = source.frames;

            sprite.frameLength = source.frameLength;

            return sprite;
        }
    }*/
    }
}
